﻿@using Carer.Crm.ViewModel
@using Carer.Data.Enum
@model IndexModel
@{
    var filterAllUnits = Model.UserUnit == null ? Model.AllUnits : Model.AllUnits.Where(it => it.Id != Model.UserUnit.Id);
}

@if (Model.Role == EnumRole.Platform_Manager)
{
    <li class="menu">
        @if (Model.UserUnit != null)
        {
            <a href="javascript:void(0)">@Model.UserUnit.Name<i class="fa fa-caret-down" data="@Model.UserUnit.Id"></i></a>
        }
        else
        {
            <a href="javascript:void(0)">未选择 <i class="fa fa-caret-down"></i></a>
        }
        <div class="sub">
            <ul>
                @foreach (var unit in filterAllUnits)
                {
                    <li><a href="/Home/SwitchUnit/@unit.Id">@unit.Name</a></li>
                }

            </ul>
        </div>
    </li>
}
else
{
    if (Model.UserUnit == null)
    {
        <li>
            <a href="javascript:void(0)">未选择 <i class="fa fa-caret-down"></i></a>
        </li>
    }
    else
    {   <li>
        <a href="#"> @Model.UserUnit.Name<i class="fa fa-caret-down" data="@Model.UserUnit.Id"></i></a>
    </li>
    }
}

<script type="text/javascript">
    $(function () {
        window.UserUnit = {
            Id: $(".fa-caret-down").attr("data"),
            Role: '@((int)Model.Role)'
        };
    });
</script>